import request from '@/utils/request'

const baseApi = function(url) {
  return {
    list: (query) => request({ url: url, method: 'get', params: query }),
    update: (data, uuid) => request({ url: `${url}${uuid}/`, method: 'patch', data }),
    create: (data) => request({ url: url, method: 'post', data }),
    delete: (uuid) => request({ url: `${url}${uuid}/`, method: 'delete' }),
    retrieve: (uuid) => request({ url: `${url}${uuid}/`, method: 'get' })
  }
}

export const specialProjectOp = baseApi('/project/special-projects/')
specialProjectOp.uploadExcel = (queryset) => request({ url: '/project/special-projects/excel/', data: { queryset }, method: 'post' })

export const runningExpenditureOp = baseApi('/project/running-expenditures/')
runningExpenditureOp.uploadExcel = (queryset) => request({ url: '/project/running-expenditures/excel/', data: { queryset }, method: 'post' })

export const userOp = baseApi('/users/')

userOp.resetPassword = (uuid) => request({ url: `/users/${uuid}/reset-password/`, method: 'post' })
userOp.setReadOnly = (uuid, is_readonly_all) => request({ url: `/users/${uuid}/set-readonly/`, method: 'post', data: { is_readonly_all }})
userOp.changePassword = (data) => request({ url: `/users/change-password/`, method: 'post', data })

